const btn_openNew = document.querySelector("#openNew");
const { remote, ipcRenderer, shell } = require("electron");
const { BrowserWindow, BrowserView } = remote;

window.onload = () => {
  let win;
  btn_openNew.onclick = () => {
    win = new BrowserWindow({
      width: 500,
      height: 500,
      title: "请注意加载的路径",
      webPreferences: {
        nodeIntegration: true,
        enableRemoteModule: true,
      },
    });

    //win.loadFile('./red.html')
    //win.loadFile('./render-process/red.html')
    win.loadFile("./src/render-process/red.html");

    win.on("close", () => {
      win = null;
    });
  };
};

var rigthMenuTemplate = [
  {
    label: "复制",
    accelerator: "ctrl+c",
  },
  {
    label: "粘贴",
    accelerator: "ctrl+v",
  },
  {
    label: "调试窗口",
    accelerator: "ctrl+sift+I",
    click: () => {
      console.log("调试窗口click");
      ipcRenderer.send("openDevTools", {});
    },
  },
];
console.log(remote);
const m = remote.Menu.buildFromTemplate(rigthMenuTemplate);

window.addEventListener("contextmenu", (e) => {
  console.log("xxxx");
  //alert('red.html');
  e.preventDefault();
  m.popup({
    window: remote.getCurrentWindow(),
  });
});

const btn_windowOpen = document.querySelector("#windowOpen");

btn_windowOpen.onclick = () => {
  window.open("./render-process/red.html");
};
const btn_openDialogDemo = document.querySelector("#openDialogDemo");

btn_openDialogDemo.onclick = () => {
  let win;
  win = new BrowserWindow({
    width: 500,
    height: 500,
    title: "Open Dialog Demo",
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
    },
  });

  //win.loadFile('./red.html')
  //win.loadFile('./render-process/red.html')
  win.loadFile("./src/render-process/dialog.html");

  win.on("close", () => {
    win = null;
  });
};

const btn_pdfdemoPage = document.querySelector("#pdfdemoPage");

btn_pdfdemoPage.onclick = () => {
  let win;
  console.log(win);
  win = new BrowserWindow({
    width: 800,
    height: 600,
    title: "Open Dialog Demo",
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
    },
  });

  //win.loadFile('./red.html')
  //win.loadFile('./render-process/red.html')
  win.loadFile("./src/render-process/pdf.html");

  win.on("close", () => {
    win = null;
  });

  //const BrowserView = electron.BrowserView;
  console.log(BrowserView);
  const view = new BrowserView();
  view.setAutoResize({ width: true, height: true });
  win.setBrowserView(view);
  view.setBounds({
    x: 0,
    y: 0,
    width: 800,
    height: 600,
    title: "aaa",
  });
  view.webContents.loadURL(
    "http://qiniu.nxycdl.com/nxsiwk/%E9%9B%86%E9%87%87%E9%9D%9E%E4%B8%AD%E9%80%89%E6%94%AF%E4%BB%98%E6%A0%87%E5%87%86196%E5%8F%B7%281%29.pdf"
  );
};

const btn_pdfStremdemoPage = document.querySelector("#pdfStremdemoPage");

btn_pdfStremdemoPage.onclick = () => {
  let win;
  console.log(win);
  win = new BrowserWindow({
    width: 800,
    height: 600,
    title: "Open Dialog Demo",
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
    },
  });
  win.webContents.openDevTools();
  //win.loadFile('./red.html')
  //win.loadFile('./render-process/red.html')
  win.loadFile("./src/render-process/pdfStream.html");

  win.on("close", () => {
    win = null;
  });
};
const btn_showReport = document.querySelector("#showReport");

btn_showReport.onclick = () => {
  let win;
  console.log(win);
  win = new BrowserWindow({
    width: 800,
    height: 600,
    title: "showReport",
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
    },
  });
  //win.webContents.openDevTools();
  //win.loadFile('./red.html')
  //win.loadFile('./render-process/red.html')
  win.loadFile("./src/render-process/1#2.html");

  win.on("close", () => {
    win = null;
  });
};
